package com.shenyong.ladmin.controller;

import com.shenyong.ladmin.entity.Article_Kind;
import com.shenyong.ladmin.logConfig.Log;
import com.shenyong.ladmin.logConfig.OperationType;
import com.shenyong.ladmin.service.Article_KindService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 后台种类管理
 * kindFindPage
 * kindSave
 * kindDelete
 */
@RestController
public class Article_KindController {
  @Resource
  private Article_KindService article_kindService;
  @RequiresAuthentication
  @ApiOperation(value = "查询种类", notes = "分页查询种类", produces = "application/json")
  @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "起始行", required = false, dataType = "int")
          , @ApiImplicitParam(name = "limit", value = "显示多少条数据", required = false, dataType = "int")})
  @RequestMapping("kindFindPage")
  public Map<String, Object> kindFindPage(int page, int limit, String kind_name) {
    Map<String, Object> mapa = new HashMap<String, Object>();
    mapa.put("page", (page - 1) * limit);
    mapa.put("limit", limit);
    System.out.println(kind_name+"为欢几何");
    mapa.put("kind_name",kind_name);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", "");
    map.put("msg", 0);
    map.put("count", article_kindService.article_KindCount(mapa));
    map.put("data", article_kindService.article_KindAll(mapa));
    return map;
  }
  @RequiresAuthentication
  @Log(describe = "添加种类",operationType= OperationType.INSERT)
  @RequestMapping("kindSave")
  public Object kindSave(Article_Kind article_kind) {
    System.out.println(article_kind+"article_kind");
    if (article_kind.getKind_id() == null || article_kind.getKind_id().equals(0)){
      article_kind.setKind_number(0);
      return article_kindService.article_KindAdd(article_kind);}
    else{
      return article_kindService.article_KindUpdate(article_kind);
    }
  }
  @RequiresAuthentication
  @Log(describe = "删除种类",operationType= OperationType.DELETE)
  @RequestMapping("kindDelete")
  public Object kindDelete(int aid) {
    return article_kindService.article_KindDelete(aid);
  }
}
